
# 维护管理员相关的接口

from api.base import Base
from loguru import logger

class UserManagerApi(Base):

    # 构造方法
    def __init__(self):
        self.add_user_url = self.get_url('/admin/admin/create')
        self.edit_user_url = self.get_url('/admin/admin/update')
        self.search_user_url = self.get_url('/admin/admin/list?page=1&limit=20&sort=add_time&order=desc')
        self.delete_user_url = self.get_url('/admin/admin/delete')

    # 新增管理员
    def add_user(self,username,password,**kwargs):
        user_data = {'username':username,'password':password}
        if kwargs:
            logger.info("添加管理员的可选参数:{}".format(kwargs))
            user_data.update(kwargs)
        return self.post(self.add_user_url,user_data)

    # 修改管理员
    def update_user(self,id,username,password,**kwargs):
        user_data = {'id':id,'username':username,'password':password}
        if kwargs:
            user_data.update(kwargs)
        return self.post(self.edit_user_url,user_data)

    # 删除管理员
    def delete_user(self,id,username,**kwargs):
        user_data = {'id': id, 'username': username}
        if kwargs:
            user_data.update(kwargs)
        return self.post(self.delete_user_url, user_data)

    # 查询管理员
    def search_user(self):
        return self.get(self.search_user_url)


if __name__ == '__main__':

    user = UserManagerApi()
    user.login()
    print(user.search_user())
    print(user.add_user('test001','test001'))